/*
 	Software Author: Mike Moore
 	Vectrics Flashrecruit
 	Open source job board and applicant tracking system.  Built with enterprise Java.
 	GPL License applies to this source code.
 */
package org.vectrics.struts;


import java.util.*;

import org.apache.log4j.Logger;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.MessageResourcesFactory;
import org.vectrics.provider.CoreServiceLocator;



public class PhraseManager implements PhraseProvider {
	public static String NOT_GIVEN_CODE = "not.given";
	private Logger log = Logger.getLogger(this.getClass());


	public String getMessage(String code, Locale locale) {
		MessageResourcesFactory factory = MessageResourcesFactory.createFactory();
		MessageResources messageResources = factory.createResources(
					"ApplicationResources");
		String message = "Missing String for Code: " + code;
		message = messageResources.getMessage(locale, code);
		if (message == null)
			if (locale != null) {
				message = "ERROR - COULD NOT FIND CODE: " + code  + "  LOCALE = " + locale.getDisplayName();
				log.warn(message);
			} else {
				message = "ERROR - COULD NOT FIND CODE: " + code  + "  LOCALE NOT GIVEN";
				log.warn(message);
			}
		return(message);
	}
	
	public String getMessage(String code, Locale locale, Object[] args) {
		MessageResourcesFactory factory = MessageResourcesFactory.createFactory();
		MessageResources messageResources = factory.createResources(
					"ApplicationResources");
		String message = "Missing String for Code: " + code;
		message = messageResources.getMessage(locale, code, args);
		if (message == null)
			if (locale != null) {
				message = "ERROR - COULD NOT FIND CODE: " + code  + "  LOCALE = " + locale.getDisplayName();
				log.warn(message);
			} else {
				message = "ERROR - COULD NOT FIND CODE: " + code  + "  LOCALE NOT GIVEN";
				log.warn(message);
			}
		return(message);
	}
	
	public static String getNotGiven(Locale locale) {
		return(CoreServiceLocator.getPhraseProvider().getMessage(PhraseManager.NOT_GIVEN_CODE, locale));
	}
	
}
